unit Srvr_Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
  Modl_HTTP;

type
  TSRVRPRMS = class(TService)
    procedure ServiceShutdown(Sender: TService);
    procedure ServiceStart(Sender: TService; var Started: Boolean);
    procedure ServiceStop(Sender: TService; var Stopped: Boolean);
  private
    FIsRunning:Boolean;
  public
    function  GetServiceController: TServiceController; override;
    procedure StartService;
    procedure StopService;    
  end;

var
  SRVRPRMS: TSRVRPRMS;

const
  CONST_SRVR_NAME='SRVRPRMS';

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  SRVRPRMS.Controller(CtrlCode);
end;

function TSRVRPRMS.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TSRVRPRMS.ServiceShutdown(Sender: TService);
begin
  StopService;
end;

procedure TSRVRPRMS.ServiceStart(Sender: TService;
  var Started: Boolean);
begin
  StartService;
  Started:=FIsRunning;
end;

procedure TSRVRPRMS.ServiceStop(Sender: TService;
  var Stopped: Boolean);
begin
  StopService;
  Stopped:=not FIsRunning;
end;

procedure TSRVRPRMS.StartService;
begin
  if not FIsRunning then
  begin
    ModlHHTP.Start;
    FIsRunning := True;
  end;
end;

procedure TSRVRPRMS.StopService;
begin
  if FIsRunning then
  begin
    ModlHHTP.Stop;
    FIsRunning := False;
  end;
end;

end.
 